<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" content="ie=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>配置信息</title>
<#include "../common/easyui-html5.ftl"/>
</head>
<body class="easyui-layout">
	 <div data-options="region:'center'">
		<table id="dg"></table>
	</div>
	<!-- 工具条  -->
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<table width="100%">
			<tr width="100%">
				<td width="50%">
					名称: <input class="easyui-textbox" style="line-height:12px; width:200px" id="s_proName"/>
					<!--
					状态:<select class="easyui-combobox" data-options="editable:false,panelHeight:'auto'" style="width:100px" id="role_status">
						<option value="0">不限</option>
						<option value="1">有效</option>
						<option value="2">待审核</option>
						<option value="3">锁定</option>
					</select> -->
					<a href="#"  class="easyui-linkbutton" iconCls="icon-search" onclick="searchFn()">查询</a>
				</td>
				<td align="right" width="50%">
					<a id="addBtn" href="#" class="easyui-linkbutton" iconCls="add_btn" plain="true" onclick="addFn()">增加</a>
				</td>
			</tr>
		</table>
		</div>
	</div>
	<!-- 弹出窗口  -->
	<div id="w" class="easyui-window"
		data-options="modal:true,closed:true,iconCls:'icon-save',
		collapsible:false,minimizable:false,maximizable:false,resizable:false"
			style="width:500px;height:420px;padding:10px;">
			<div class="easyui-layout" data-options="fit:true">

					<div data-options="region:'center',border:false" style="padding:10px;">
                        <form id="form1" method="post">
                            <input type="hidden" name="isAjax" value="1"/>
                        <table>
                            <tr style="display: none;">
                                <td>id:</td>
                                <td><input  type="text" id="form_id" name="id"></input></td>
                            </tr>
                            <tr  >
                                <td>属性名</td>
                                <td><input  type="text" id="proName" name="proName" class="easyui-textbox" data-options="" style="width:300px"></input></td>
                            </tr>
                            <tr id="tr_pro"  >
                                <td>&nbsp;</td>
                                <td>系统属性名不允许修改</td>
                            </tr>
                            <tr  >
                                <td>属性值</td>
                                <td><input  type="text" id="proValue" name="proValue" class="easyui-textbox" data-options="" style="width:300px"></input></td>
                            </tr>
                            <tr  >
                                <td>属性描述</td>
                                <td><input  type="text" id="proDesc" name="proDesc" class="easyui-textbox" data-options="multiline:true,height:50" style="width:300px"></input></td>
                            </tr>


                        </table>
                        </form>
					</div>
					<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
						<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:submitForm()">保存</a>
						<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:closeWinFn()">取消</a>
					</div>

			</div>
	</div>
<script type="text/javascript">
var doPage =  authIds.indexOf(",admin_dbconfig_dopage,")>=0?true:false;
var doAddBtn =   authIds.indexOf(",admin_dbconfig_doadd,")>=0?true:false;
var doupdateBtn =  authIds.indexOf(",admin_dbconfig_doupdate,")>=0?true:false;
var dodelBtn =  authIds.indexOf(",admin_dbconfig_dodel,")>=0?true:false;
var saveType="add";
$(function(){
			if(!doAddBtn){
				$("#addBtn").hide();
			}
			$('#dg').datagrid({
			 	border:false,
				rownumbers:true,
				checkOnSelect:true,
				fitColumns:true,
				pagination:true,
				singleSelect:true,
				fit:true,
				pageSize:10,
				method:'get',
			  	url:'${rc.contextPath}/admin/dbconfig/dopage?d='+new Date().getTime(),
			  	queryParams:{ },
			  	onBeforeLoad:function(param){
                    if(!doPage){
                        $.messager.alert('系统提示','您没有权限访问!','info');
                        return;
                    }
					param['pageno'] =  param['page']-1;
					param['pagesize']  = param['rows'];
			  		return true ;
			  	},
			  	onDblClickRow:function(rowIndex, rowData){
			  			//updateRowIndex = rowIndex;
						//getRoleInfoById(rowData['roleId']);
			  	},
			  	onLoadError:function(){
			  	},

				columns:[[
					{field:'id',title:'id',hidden:true},
					{field:'proName',title:'属性名' ,width:100},
                    {field:'proValue',title:'属性值' ,width:100},
                    {field:'proDesc',title:'属性描述' ,width:100},

//                    {field:'proType',title:'类型' ,width:100,formatter:function(value,row,index){
//                        if(value == "SYSTEM"){
//                            return "系统";
//                        }else if(value == "USRER") {
//                            return "自定义";
//                        }
//                    }},
					{field:'opt',title:'操作' ,width:100,formatter:optFormat}
				]],
				toolbar: '#tb',
				loadFilter:function(data){
				   if(data.statusCode == normalStatusCode){
                        	var obj = {};
                            obj.total =  data.entity.totalRows;
                            obj.rows = $.isArray(data.entity.pageData)?data.entity.pageData:[];
                            return obj;
				   }else {
				            var obj = {};
                           obj.total = 0;
                            obj.rows = [];
                            return obj;
				   }

				}
			});

			var pager = $('#dg').datagrid("getPager");
			pager.pagination({
				'onBeforeRefresh':function(){
					searchFn();
					return false;
				}
			});
		});

		function searchFn(){
			if(!doPage){
				 $.messager.alert('系统提示','您没有权限访问!','info');
				return;
			}
			var proName = $("#s_proName").val();

			$('#dg').datagrid('load',{
					//status:role_status,
                proName:proName,
					d:new Date().getTime()
			});

		}
		var resource_dg_loadSuccess = false;
		var updateRowIndex = -1;
		function addFn(){
			 saveType = "add";
            $('#form1').form('reset');
            $('#proName').textbox("enable");
            $("#tr_pro").hide();
 			 $('#w').window('open').panel('setTitle',"增加");

		}
		function delFn(id){
			$.messager.confirm('系统提示', '您确定要删除该条记录吗?', function(r){
			if (r){
					var url = "${rc.contextPath}/admin/dbconfig/dodel";
		  	 		$.ajax({
			  	  	  type:'post',
					  url: url,
					  context: document.body,
					  data:{
                          id: id,
					  	d:new Date().getTime()
					  },
					  success:function(data){

					  	if(data.statusCode == normalStatusCode){
							var row = null;
							var rows = $("#dg").datagrid("getRows");
							for(var i=0;i<rows.length;i++){
								if(rows[i]['id'] == id){
									row = rows[i];
									var rowIndex = 	$('#dg').datagrid("getRowIndex",row);
									$('#dg').datagrid("deleteRow",rowIndex);
									break;
								}
							}
					  		$.messager.alert('系统提示','删除成功!','info');

					  	}else{
					  		$.messager.alert('系统提示','删除失败，请刷新后重试!','error');
					  	}
					  },
					  error:function(xhr,textStatus,errorThrown){
					  	var responseText = xhr.responseText;
					  	$.messager.alert('系统提示','删除失败，请刷新后重试!','error');

					  }
				});

				}
			});
		}
		function optFormat (value,row,index){
			var btns = [];
			if(doupdateBtn){
				btns.push('<a class="easyui-linkbutton l-btn l-btn-plain" onclick="updateFn(\''+row['id']+'\')" href="#" plain="true" iconCls="update_btn"><span class="l-btn-left"><span class="l-btn-text update_btn l-btn-icon-left">修改</span></span></a>');
			}
			if(dodelBtn && row["proType"] != 'SYSTEM'){
				btns.push('<a class="easyui-linkbutton l-btn l-btn-plain" onclick="delFn(\''+row['id']+'\')" href="#" plain="true" iconCls="del_btn"><span class="l-btn-left"><span class="l-btn-text del_btn l-btn-icon-left">删除</span></span></a>');
			}
			return btns.join("&nbsp;");
		}
		function updateFn(id){
			updateRowIndex = -1;
			var rows = $("#dg").datagrid("getRows");
			var row = null;
			for(var i=0;i<rows.length;i++){
				if(rows[i]['id'] == id){
					row = rows[i];
					break;
				}
			}

			var rowIndex =  $('#dg').datagrid("getRowIndex",row);
			 updateRowIndex = rowIndex;
            saveType = 'update'
            $('#form1').form('reset');
            $('#form1').form('load',row);
			var proType = row['proType'];
            if(proType == "SYSTEM"){

                $('#proName').textbox("disable");
				$("#tr_pro").show();
            }else if(proType == "USRER") {

                $('#proName').textbox("enable");
                $("#tr_pro").hide();
            }
            $('#w').window('open').panel('setTitle',"修改品牌");

		}

		function submitForm(){
			 var isValidate = $('#form1').form('validate');
			 if(!isValidate){
			 	$.messager.alert('系统提示','请确保填写正确!','warning');
			 	return;
			 }
            var proName = $.trim($("#proName").textbox("getValue"));
            var proValue = $.trim($("#proValue").textbox("getValue"));

			if(proName.length ==0 ){
				$.messager.alert('系统提示','属性名称不能为空!','warning');
				return;
			}

            var url =  "${rc.contextPath}/admin/dbconfig/doadd";
			if(saveType == 'add'){

			}else if(saveType == 'update'){
                url =  "${rc.contextPath}/admin/dbconfig/doupdate";
			}

            $('#form1').form('submit', {
                        url:url,
				onSubmit: function(param){
						//param.p1 = 'value1';
						//param.p2 = 'value2';

                    jQuery.showMask($("#w")[0],"正在保存中 ....");
					return true;

				},
                success: function(data){
                    jQuery.hideMask($("#w")[0]);
                    data = eval("("+data+")");
                    if(data.statusCode == normalStatusCode){
                        $('#dg').datagrid('reload');
                        $.messager.alert('系统提示','保存成功!','info',closeWinFn);
                    }else{
                        var errorEntity = data.entity;
                        if(errorEntity){
                            $.messager.alert('系统提示','保存失败,'+errorEntity.errorMsg,'warning');
                        }else{
                            $.messager.alert('系统提示','保存失败!','warning');
                        }
                    }
                  //  var data = eval('(' + data + ')');  // change the JSON string to javascript object
                }
        });
		}

		function closeWinFn(){
			$('#w').window('close');
		}


	</script>
</body>
</html>